<?php
// +--------------------------------------------------------------------------
// | ZAIYOUDAO [ 载攸道 先顺得常 ] <http://www.zaiyoudao.com>
// +--------------------------------------------------------------------------
// | Copyright © 2009-2016 载攸道 版权所有 <TEL:17090888854>
// +--------------------------------------------------------------------------
// | Project: YiPHP [ 我会的仅仅是偷懒！ ] <http://www.yiphp.com>
// +--------------------------------------------------------------------------
// | Author: 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>
// +--------------------------------------------------------------------------

/**
 * 我的信息
 */
namespace Research\Controller;
use Common\Controller\AdminController;

/**
 * 我的控制器
 */
class FinanceController extends AdminController{
	
	/**
	 * 修改信息
	 */
    public function Transfer(){

		common_public()->assign_page('财务转账');
		
		$m_common_user = M('common_user');
			
		$map['id'] = getUID();
			
		if(IS_AJAX){
			
			action_log('admin_my_info_edit');//行为记录
		
			$data = I('');
			
			$result = $m_common_user->where($map)->save($data);
	
			//返回信息
			$info = $result?get_errcode(0):get_errcode(10000002);
			
			$this->ajaxReturn($info);
			
		}else{
			
			action_log('admin_my_info_view');//行为记录
		
			$data = $m_common_user->where($map)->find();
			
			$this->assign('data',$data);
			
			$this->display();
		}
		
		
	}
	
	/**
	 * 修改信息
	 */
    public function gogo(){

		$m_common_user = M('common_user');
		$m_mall_integral = M('mall_integral');
			
		$map['id'] = getUID();
			
		$data = $m_common_user->where($map)->find();
		
	
			
			
		$value = '提现'.$data['integral'].'账户：'.$data['nickname'].' 账号：'.$data['email'];
		integralLog($data['id'],$data['integral'],2,$value,2,2);
	
		
			
			
		$this->ajaxReturn(get_errcode(0));
			
		
		
		
	}
	
	/**
	 * 修改信息
	 */
    public function goTransfer(){

		$m_common_user = M('common_user');
		$m_mall_integral = M('mall_integral');
			
		$map['id'] = getUID();
			
		$data = $m_common_user->where($map)->find();
		
	
			//判断积分
			$integral = I('param.integral','','');
			
			if($integral>$data['integral']){
				
				
				
				$this->ajaxReturn(get_errcode(50000001));
				die;
			}
			
			//判断用户
			$umap['id'] = I('param.uid','','');
			
			$udata = $m_common_user->where($umap)->find();
			
			if(!$udata){
				
				
				
				$this->ajaxReturn(get_errcode(50000002));
				die;
			}
			
			$value = 'UID'.$data['id'].'转账'.$integral;
			integralLog($udata['id'],$integral,1,$value,1,1);
			
			$value = '转给(UID'.$udata['id'].')'.$integral;
			integralLog($data['id'],$integral,2,$value,1,1);
		
		
			
			
			$this->ajaxReturn(get_errcode(0));
			
		
		
		
	}
	
	/*
	 * 用户管理
	 */
    public function Detail(){
		
		action_log('admin_user_manage');//行为记录
		
		common_public()->assign_page('财务明细');
		
		
		$m_common_user = M('common_user');
		$m_mall_integral = M('mall_integral');
		
	
		
		//用户状态
 		$status_info = array(
		
			'1' 	  => '启用中',
			'2' 	  => '停用中',
			
			
		);
		
		
		
		
		//用户UID
		$uid = I('param.uid')?I('param.uid'):'';

		if($uid!=0){
			
			$map['id'] =array('like',"%$uid%");
		}
		
		//selected="selected"
		$this->assign('uid',$uid);
		
		
		//开始结束时间
		//金额区间
		$begin_time = strtotime(I('param.begin_time'));
		$end_time = strtotime(I('param.end_time'));
		if($begin_time != null and $end_time != null){
			
			$map['time']  = array(array('egt',$begin_time),array('elt',$end_time),'and'); 
			
		}else{
			
			$begin_time=time();
			$end_time=time()+86400;
		}
		
		
		$this->assign('begin_time',$begin_time);
		$this->assign('end_time',$end_time);
		
	
		
		$map['uid'] = getUID();
	
		$_GET['p']=$_GET['p']?$_GET['p']:1;
		
		$list = $m_mall_integral->where($map)->order('time desc')->page($_GET['p'].',50')->select();
		$count      = $m_mall_integral->where($map)->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出
		$this->assign('pages',$show);
		
		
		$this->assign('list',$list);
		
		
		$this->display();
	}
	
	/*
	 * 用户管理
	 */
    public function Log(){
		
		action_log('admin_user_manage');//行为记录
		
		common_public()->assign_page('提现明细');
		
		
		$m_common_user = M('common_user');
		$m_mall_integral = M('mall_integral');
		
	
		
		//用户状态
 		$status_info = array(
		
			'1' 	  => '启用中',
			'2' 	  => '停用中',
			
			
		);
		
		
		
		
		//用户UID
		$uid = I('param.uid')?I('param.uid'):'';

		if($uid!=0){
			
			$map['id'] =array('like',"%$uid%");
		}
		
		//selected="selected"
		$this->assign('uid',$uid);
		
		
		//开始结束时间
		//金额区间
		$begin_time = strtotime(I('param.begin_time'));
		$end_time = strtotime(I('param.end_time'));
		if($begin_time != null and $end_time != null){
			
			$map['time']  = array(array('egt',$begin_time),array('elt',$end_time),'and'); 
			
		}else{
			
			$begin_time=time();
			$end_time=time()+86400;
		}
		
		
		$this->assign('begin_time',$begin_time);
		$this->assign('end_time',$end_time);
		
	
		
		$map['type'] = 2;
		$map['type_value'] = 2;
		//$map['uid'] = getUID();
	
		$_GET['p']=$_GET['p']?$_GET['p']:1;
		
		$list = $m_mall_integral->where($map)->order('time desc')->page($_GET['p'].',50')->select();
		$count      = $m_mall_integral->where($map)->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出
		$this->assign('pages',$show);
		
		
		$this->assign('list',$list);
		
		
		$this->display();
	}
	
	/*
	 * 编辑用户信息
	 */
	public function Status($id,$status=0){
		
		//判断是否是ajax请求
		if(IS_AJAX){
				
			$m_mall_integral = M('mall_integral');
		
			$id = $id?$id:I('param.id');
			$status = $status?$status:I('param.status');
			
			
			if($id){
				
			
				$id = explode(',',$id); 
				
				
				foreach($id as $i=>$k){
					
					$map['id'] = $id[$i];
					
					
						
						
						$data['status'] = $status;
			
						$m_mall_integral->where($map)->save($data);
					
					}
					
					
					
			
				//返回信息
				$info = get_errcode(0);
			
			}else{
				
				$info = get_errcode(10000001);
			}
			
	
		
		}
		
		//返回信息		
		$info = $info?$info:get_errcode(-2);

		$this->ajaxReturn($info);


	}
	
}